package com.iotimc.attendancesystem.entity;

import org.greenrobot.greendao.annotation.Convert;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.converter.PropertyConverter;

/**
 * @author david
 * @date 2017/11/27
 */
@Entity
public class BasicSettingEntity {
    public enum DeviceType {
        /**
         * DEFAULT 空属性
         * ATTENDANCES 考勤机
         * DOOR 开门机
         */
        DEFAULT(0),MANUAL_DOOR(1), AUTO_DOOR(2);
        /**
         * 使用稳定的 id 来转换，不要使用不稳定的名字和顺序
         */
        final int id;

        DeviceType(int id) {
            this.id = id;
        }
    }

    public enum ButtonType{
        /**

         * DOOR_BELL 门铃
         * OPEN_DOOR 开门按钮
         */
        DOOR_BELL(1), OPEN_DOOR(2);
        /**
         * 使用稳定的 id 来转换，不要使用不稳定的名字和顺序
         */
        final int id;

        ButtonType(int id) {
            this.id = id;
        }
    }

    @Id
    private long id = 0;
    /**
     * 按钮类型
     */
    @Convert(converter = ButtonTypeConverter.class,columnType = Integer.class)
    private ButtonType buttonType = ButtonType.DOOR_BELL;
    /**
     * 设备类型
     */
    @Convert(converter = DeviceTypeConverter.class, columnType = Integer.class)
    private DeviceType deviceType = DeviceType.DEFAULT;
    /**
     * 公司名称
     */
    private String companyName;
    /**
     * 考勤间隔时间
     */
    private int time = 10;
    /**
     * 门禁联网ip
     */
    private String doorIp;
    /**
     * 相似度（验证人脸的最低分数   60-100）
     */
    private int similarityScore = 60;
    /**
     * 延迟关门的时间（单位秒）
     */
    private int delayDoorSecond = 30;
    /**
     * 超级密码
     */
    private String password = "123456";

    @Generated(hash = 653244076)
    public BasicSettingEntity(long id, ButtonType buttonType, DeviceType deviceType, String companyName,
            int time, String doorIp, int similarityScore, int delayDoorSecond, String password) {
        this.id = id;
        this.buttonType = buttonType;
        this.deviceType = deviceType;
        this.companyName = companyName;
        this.time = time;
        this.doorIp = doorIp;
        this.similarityScore = similarityScore;
        this.delayDoorSecond = delayDoorSecond;
        this.password = password;
    }

    @Generated(hash = 408279840)
    public BasicSettingEntity() {
    }

    public long getId() {
        return this.id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public DeviceType getDeviceType() {
        return this.deviceType;
    }

    public void setDeviceType(DeviceType deviceType) {
        this.deviceType = deviceType;
    }

    public String getCompanyName() {
        return this.companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public int getTime() {
        return this.time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public String getDoorIp() {
        return this.doorIp;
    }

    public void setDoorIp(String doorIp) {
        this.doorIp = doorIp;
    }

    public int getSimilarityScore() {
        return this.similarityScore;
    }

    public void setSimilarityScore(int similarityScore) {
        this.similarityScore = similarityScore;
    }

    public int getDelayDoorSecond() {
        return this.delayDoorSecond;
    }

    public void setDelayDoorSecond(int delayDoorSecond) {
        this.delayDoorSecond = delayDoorSecond;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public ButtonType getButtonType() {
        return this.buttonType;
    }

    public void setButtonType(ButtonType buttonType) {
        this.buttonType = buttonType;
    }

    public static class ButtonTypeConverter implements PropertyConverter<ButtonType,Integer>{

        @Override
        public ButtonType convertToEntityProperty(Integer databaseValue) {
            if (databaseValue == null) {
                return null;
            }
            for (ButtonType buttonType : ButtonType.values()) {
                if (buttonType.id == databaseValue) {
                    return buttonType;
                }
            }
            return ButtonType.DOOR_BELL;
        }

        @Override
        public Integer convertToDatabaseValue(ButtonType entityProperty) {
            return entityProperty == null ? null : entityProperty.id;
        }
    }

    public static class DeviceTypeConverter implements PropertyConverter<DeviceType, Integer> {

        @Override
        public DeviceType convertToEntityProperty(Integer databaseValue) {
            if (databaseValue == null) {
                return null;
            }
            for (DeviceType deviceType : DeviceType.values()) {
                if (deviceType.id == databaseValue) {
                    return deviceType;
                }
            }
            // 准备一个默认值，防止数据移除时崩溃
            return DeviceType.DEFAULT;

        }

        @Override
        public Integer convertToDatabaseValue(DeviceType entityProperty) {
            return entityProperty == null ? null : entityProperty.id;
        }
    }
}
